/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.travelFinder.controller;

import com.travelFinder.domain.ConnectionType;
import com.travelFinder.domain.TrainConnection;
import com.travelFinder.service.DbPopulator;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author Kryl
 */
@Controller
public class ConnectionController {
        
    @Autowired private DbPopulator populator;
    
    static String data_dir="C:\\Users\\Kryl\\Documents\\RSO\\rso-12l-graph-database\\test-app\\csvFiles";
    
    @RequestMapping(value = "/populate", method = RequestMethod.GET)
    public @ResponseBody String populateDatabase() throws IOException {
        ArrayList<InputFileEntry> list = new ArrayList<InputFileEntry>();
           
      list.add(new InputFileEntry("PKP IC",new TrainConnection(), new File(data_dir+File.separator+"polaczenia0.txt")));
    /*  list.add(new InputFileEntry("PKP IC",new TrainConnection(),new File(data_dir+File.separator+"polaczenia1.txt")));
      list.add(new InputFileEntry("PKP IR",new TrainConnection(),new File(data_dir+File.separator+"polaczenia2.txt")));
      list.add(new InputFileEntry("PKP IC",new TrainConnection(),new File(data_dir+File.separator+"polaczenia3.txt")));
      list.add(new InputFileEntry("PKP IC",new TrainConnection(),new File(data_dir+File.separator+"polaczenia4.txt")));
      list.add(new InputFileEntry("PKP TLK",new TrainConnection(),new File(data_dir+File.separator+"polaczenia5.txt")));
	  list.add(new InputFileEntry("PKP TLK",new TrainConnection(),new File(data_dir+File.separator+"polaczenia6.txt")));
	  list.add(new InputFileEntry("PKS",new BusConnection(),new File(data_dir+File.separator+"polaczenia7.txt")));
	  list.add(new InputFileEntry("PKS",new BusConnection(),new File(data_dir+File.separator+"polaczenia8.txt")));*/
	  
        populator.populateDatabase(list);
      
        return "Załadowano";
    }
    static public class InputFileEntry{
        final private String company;
        final private ConnectionType type;
        final private File file;

        public InputFileEntry(String company, ConnectionType type, File file) {
            this.company = company;
            this.type = type;
            this.file = file;
        }

        /**
         * @return the company
         */
        public String getCompany() {
            return company;
        }

        /**
         * @return the type
         */
        public ConnectionType getType() {
            return type;
        }

        /**
         * @return the file
         */
        public File getFile() {
            return file;
        }
        
    }
}

